<?PHP
session_start();
include("common/connect.php");
include("common/common.php");

if( !isset($_SESSION["user"]) ) 
{
	$url = "Location:login.php?ref=find_item.php";
	header($url);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body,td,th {
	font-family: 宋体;
	font-size: 13px;
	color: #000;
}
body {
	background-color: #FFF;
}
.STYLE1 {
	font-size: x-large;
	font-weight: bold;
}
-->
</style>
<script language="javascript">
function OnFind()
{
	var input_item = document.getElementById("input_item").value;
 	var input_tradeid = document.getElementById("input_tradeid").value;
	var input_tbid = document.getElementById("input_tbid").value;
	window.location.href= "find_item.php?input_item=" + input_item + "&input_tradeid=" + input_tradeid + "&input_tbid=" + input_tbid;
}
</script>
</head>

<body>

<div align="center" class="STYLE1">查找后台</div>
<br>
<table cellpadding="0" cellspacing="0" border="1" align="center">
	<tr>
    	<td colspan="9" height="22"><a href="view_report.php">客户端上报的</a></td>
    </tr>
	<tr>
    	<td height="25" width="50" align="center">序列号</td>
        <td width="200" align="center">时间</td>
      	<td width="198" align="center">产品Id</td>
        <td width="70" 	align="center">返现(元)</td>
        <td width="144" align="center">交易流水号</td>
        <td width="158" align="center">支付宝帐号</td>
        <td width="113" align="center">ip</td>
        <td width="60" align="center">转换</td>
        <td width="143" align="center">操作</td>
    </tr>
<?php
$input_item = trim(CheckUrlParamNoDie( "input_item" ));
$input_tbid = trim(CheckUrlParamNoDie( "input_tbid" ));
$input_tradeid = trim(CheckUrlParamNoDie( "input_tradeid" ));
$tradeid_begin = substr($input_tradeid, 0, 6);
$tradeid_end = substr($input_tradeid, -4);
//$input_tradeid_sql = substr($input_tradeid, 0, 7);
$opt = trim(CheckUrlParamNoDie( "opt" ));
$id = SetUrlParamInt("id");
$find_flag = $input_item != "" || $input_tradeid != "" || $input_tbid != "";

if( $input_item != "" )
{
	$sql = "select * from trade where item_id='$input_item' order by id desc";
	$result = mysql_query( $sql );
}
else if( $input_tradeid != "" )
{
	$sql = "select * from trade where trade_id like '".$tradeid_begin."%".$tradeid_end."' order by id desc";
	$result = mysql_query( $sql );
}
else if( $input_tbid != "" )
{
	$sql = "select * from trade where tb_id = '$input_tbid' order by id desc";
	$result = mysql_query( $sql );
}


// 默认浏览器
if( $opt == "ie_hide" )
{
	$sql = "update other_trade set state=1 where id=$id limit 1";
	mysql_query( $sql );
	echo "<script>window.history.back()</script>";
	exit;
}
if( $opt == "ie_del" )
{
	$sql = "delete from other_trade where id=$id";
	mysql_query( $sql );
	echo "<script>window.history.back()</script>";
	exit;
}

// 手工申请的
if ($opt == "manul_del")
{
	$sql = "delete from feedback where id=$id";
	mysql_query( $sql );
	echo "<script>alert(\"删除成功！\");window.history.back()</script>";
	exit;
}

//
if( $id != 0 && $opt == "returnall" )
{
	$sql = "update trade set has_return=1 where id=$id limit 1";
	mysql_query( $sql );
	//header("Location:view_discount.php?showtype=".$showtype);
	echo "<script>window.history.back()</script>";
	exit;
}

//部分返现
if( $id != 0 && $opt == "returnpart" )
{
	$sql = "update trade set has_return=2 where id=$id limit 1";
	mysql_query( $sql );
	//header("Location:view_discount.php?showtype=".$showtype);
}

while( $find_flag && $row = mysql_fetch_assoc( $result ) )
{
	if( $row["use_discount"] == "1" )
		$use_discount = "<strong><span style=\"color:#F00\">是</span></strong>";
	else
		$use_discount = "否";
?>
<tr title="<?PHP echo $row["info"]; ?>" bgcolor="<?PHP if ($row["has_return"] == 1) echo "#33CCFF"; else if ($row["has_return"] == 2) echo "#CC6666"; ?>">
    <td height="25" width="50" align="center"><?PHP echo $row["id"]; ?></td>
    <td width="200" align="center" title=""><?PHP echo $row["time"]; ?></td>
	<td width="198" align="center"><?PHP echo $row["item_id"]; ?>&nbsp;</td>
	<td width="70" 	align="center"><?PHP echo $row["discount"]; ?>&nbsp;</td>
	<td width="144" align="center"><?PHP echo $row["trade_id"]; ?>&nbsp;</td>
	<td width="158" align="center"><?PHP echo $row["tb_id"]; ?>&nbsp;</td>
    <td width="113" align="center"><?PHP echo $row["ip"]; ?>&nbsp;</td>
    <td width="60" align="center"><?PHP echo $use_discount; ?>&nbsp;</td>
	<td width="143" align="center">
    	<a href="find_item.php?opt=returnall&input_item=<?PHP echo $input_item; ?>&id=<?PHP echo $row["id"]; ?>">标志返现</a>&nbsp;&nbsp;
    </td>
</tr>
<?PHP
}
?>
</table>
<br /><br />

<table cellpadding="0" cellspacing="0" border="1" align="center">
	<tr>
    	<td colspan="11" height="22"><a href="record_list.php">已返现的(旧数据4月28号前的)</a></td>
    </tr>
	<tr>
    	<td height="25" width="50" align="center">序列号</td>
        <td width="118" align="center">时间</td>
      	<td width="300" align="center">产品Id</td>
        <td width="68" 	align="center">共返现</td>
        <td width="76" align="center">成交额</td>
        <td width="76" align="center">已返现</td>
        <td width="166" align="center">支付宝帐号</td>
        <td width="100" align="center">订单号</td>
        <td width="87" align="center">手机</td>
        <td width="78" align="center">全部返回</td>
		<td width="50" align="center">对应</td>
    </tr>
<?php
$tb_opt = CheckUrlParamNoDie("tb_opt");
if( $tb_opt == "1" )
{
	$id = SetUrlParamInt( "id" );
	$sql = "update return_record set state=1 where id=$id";
	mysql_query( $sql );
	echo "<script>window.history.back()</script>";
	exit;
}

if( $input_item != "" )
{
	$item = "%".$input_item."%";
	$sql = "select * from return_record where item_id like '$item' order by id desc";	
	$result = mysql_query( $sql );
}
else if( $input_tradeid != "" )
{
	$sql = "select * from return_record where trade_id like '".$tradeid_begin."%".$tradeid_end."' order by id desc";
	$result = mysql_query( $sql );
}
else if( $input_tbid != "" )
{
	$sql = "select * from return_record where tb_id = '$input_tbid' order by id desc";
	$result = mysql_query( $sql );
}

while( $find_flag && $row = mysql_fetch_assoc( $result ))
{
?>
<tr <?PHP if( $row["state"] == 1 ) 
												echo "bgcolor=\"#33CCFF\"" ?> >
    <td height="25" width="50" align="center"><?PHP echo $row["id"]; ?></td>
    <td width="118" align="center" title=""><?PHP echo $row["time"]; ?></td>
	<td width="300" align="center" title="<?PHP echo $row["item_id"]; ?>" class="text_limit"><div class="text_limit"><?PHP echo $row["item_id"]; ?></div>&nbsp;</td>
	<td width="68" 	align="center"><?PHP echo $row["all_return"]; ?>&nbsp;</td>
    <td width="76" align="center"><?PHP echo $row["price"]; ?>&nbsp;</td>
	<td width="76" align="center"><?PHP echo $row["has_return"]; ?>&nbsp;</td>
	<td width="166" align="center"><a href="view_user.php?all=1&tb_id=<?PHP echo $row["tb_id"]; ?>"><?PHP echo $row["tb_id"]; ?></a>&nbsp;</td>
    <td width="100" align="center"><?PHP echo $row["trade_id"]; ?>&nbsp;</td>
    <td width="87" align="center"><?PHP echo $row["phone"]; ?>&nbsp;</td>
	<td width="78" align="center"><?PHP echo $row["b_return"] == 1?"是":"否"; ?></td>
	<td width="78" align="center"><?PHP if( $row["state"] == 1 )
											echo "<strong><span style=\"color:#F00\">是</span></strong>";
										else 
											echo "<a href=\"find_item.php?id=".$row["id"]."&tb_opt=1&input_item=".$input_item."\">否</a>"; ?></td>
</tr>
<?PHP
}
?>
</table>

<br /><br />

<table cellpadding="0" cellspacing="0" border="1" align="center">
	<tr>
    	<td colspan="11" height="22"><a href="record_list.php">已返现的(新数据)</a></td>
    </tr>
	<tr>
    	<td height="25" width="50" align="center">序列号</td>
        <td width="118" align="center">时间</td>
        <td width="100" align="center">订单号</td>
      	<td width="300" align="center">产品Id</td>
        <td width="68" 	align="center">佣金</td>
        <td width="76" align="center">成交额</td>
        <td width="166" align="center">支付宝帐号</td>
        <td width="87" align="center">手机</td>
		<td width="50" align="center">操作人</td>
    </tr>
<?php
$tb_opt = CheckUrlParamNoDie("tb_opt");
if( $input_item != "" )
{
	$sql = "select * from order_handle_report return_record where num_iid ='$input_item' order by id desc";	
	$result = mysql_query( $sql );
}
else if( $input_tradeid != "" )
{
	$sql = "select * from order_handle_report where trade_id like '".$tradeid_begin."%".$tradeid_end."' order by id desc";
	$result = mysql_query( $sql );
}
else if( $input_tbid != "" )
{
	$sql = "select * from order_handle_report where tbid = '$input_tbid' order by id desc";
	$result = mysql_query( $sql );
}

while( $find_flag && $row = mysql_fetch_assoc( $result ))
{
?>
<tr>
    <td height="25" width="50" align="center"><?PHP echo $row["id"]; ?></td>
    <td width="118" align="center" title="<?PHP echo $row["opt_time"]; ?>"><?PHP echo $row["pay_time"]; ?></td>
	<td width="300" align="center"><?PHP echo $row["trade_id"]; ?></td>
	<td width="68" 	align="center"><?PHP echo $row["num_iid"]; ?>&nbsp;</td>
    <td width="76" align="center"><?PHP echo $row["commission"]; ?>&nbsp;</td>
	<td width="76" align="center"><?PHP echo $row["pay_price"]; ?>&nbsp;</td>
	<td width="166" align="center"><?PHP echo $row["tbid"]; ?>&nbsp;</td>
    <td width="100" align="center"><?PHP echo $row["phone"]; ?>&nbsp;</td>
    <td width="87" align="center"><?PHP echo $row["operater"]; ?>&nbsp;</td>
</tr>
<?PHP
}
?>
</table>

<br />
<br />

<table cellpadding="0" cellspacing="0" border="1" align="center">
	<tr>
    	<td colspan="11" height="22"><a href="view_feedback.php">手工申请的</a></td>
    </tr>
	<tr>
    	<td height="25" width="50" align="center">序列号</td>
        <td width="140" align="center">时间</td>
   	  <td width="143" align="center">订单号</td>
        <td width="161" align="center">支付宝帐号</td>
        <td width="268" align="center">备注</td>
	  <td width="64" align="center">操作</td>
  </tr>
<?php

if( $tb_opt == "2" )
{
	$id = SetUrlParamInt( "id" );
	$sql = "update feedback set state=1,opt_time=now(),operater='".$_SESSION["user"]."' where id=$id";
	mysql_query( $sql );
	echo "<script>window.history.back()</script>";
	exit;
}

if( $input_item != "" )
{
	$item = "%".$input_item."%";
	$sql = "select * from feedback where item_url like '$item' order by id desc";	
	$result = mysql_query( $sql );
}
else if( $input_tradeid != "" )
{
	$sql = "select * from feedback where item_url like '".$tradeid_begin."%".$tradeid_end."' or price like '".$tradeid_begin."%".$tradeid_end."' order by id desc";
	$result = mysql_query( $sql );
}
else if( $input_tbid != "" )
{
	$sql = "select * from feedback where tb_id = '$input_tbid' order by id desc";
	$result = mysql_query( $sql );
}

while( $find_flag && $row = mysql_fetch_assoc( $result ))
{
?>
	<tr title="<?PHP echo $row["info"]; ?>" <?PHP if( $row["state"] == 1 ) 
													echo "bgcolor=\"#33CCFF\"" ?> >
		<td height="25" width="50" align="center"><?PHP echo $row["id"]; ?></td>
		<td width="140" align="center" title=""><?PHP echo $row["time"]; ?></td>
	  <td width="143" align="center" title="<?PHP echo $row["item_url"]; ?>" ><?PHP echo $row["item_url"]; ?>&nbsp;</td>
      <td width="161" align="center"><?PHP echo $row["tb_id"]; ?>&nbsp;</td>
	  <td width="68" align="center"><div class="text_limit"><?PHP echo $row["info"]; ?></div>&nbsp;</td>
		<td width="41" align="center"><?PHP echo "<a href=\"find_item.php?id=".$row["id"]."&tb_opt=2&input_item=".$input_item."\">标志已处理</a>"; ?></td>
  </tr>
<?PHP
}
?>
</table>

<table cellpadding="0" cellspacing="10" border="0" align="center">
	<tr>
   	  <td width="800" height="30" align="center">
      商品ID<input type="text" value="<?PHP echo $input_item; ?>" id="input_item" size="20" onclick="javascript:select();"/>	 	  
   	  &nbsp;&nbsp;订单号<input type="text" value="<?PHP echo $input_tradeid; ?>" id="input_tradeid" size="20" onclick="javascript:select();"/>
      &nbsp;&nbsp;用户Id<input type="text" value="<?PHP echo $input_tbid; ?>" id="input_tbid" size="20" onclick="javascript:select();"/>
      <br><br>
      <input type="button" onclick="javascript:OnFind();" value="查找" style="width:300px;"/></td>
	</tr>
    <tr><td></td></tr>
</table>
</body>
</html>
